package com.common.platform.sys.base.controller.warpper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.common.platform.base.page.PageResult;
import com.common.platform.base.tree.node.MenuNode;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public abstract class BaseControllerWrapper {

    private Page<Map<String, Object>> page = null;
    private PageResult<Map<String, Object>> pageResult = null;
    private Map<String,Object> single=null;
    private List<Map<String, Object>> multi = null;

    public BaseControllerWrapper(Map<String, Object> single) {
        this.single = single;
    }

    public BaseControllerWrapper(List<Map<String, Object>> multi) {
        this.multi = multi;
    }
    public BaseControllerWrapper(Page<Map<String,Object>> page){
        if(page!=null && page.getRecords()!=null){
            this.page=page;
            this.multi=page.getRecords();

        }

    }

    public BaseControllerWrapper(PageResult<Map<String, Object>> pageResult) {
        if (pageResult != null && pageResult.getRows() != null) {
            this.pageResult = pageResult;
            this.multi = pageResult.getRows();
        }
    }

    public <T> T warp(){
        if(single!=null){
            warpTheMao(single);
        }
        if(multi!=null){
            for (Map<String,Object> map:multi){
                warpTheMao(map);
            }
        }
        if(page!=null){
            return (T) page;
        }
        if(pageResult!=null){
            return (T) pageResult;
        }
        if(single!=null){
            return (T)single;
        }
        if (multi!=null){
            return (T)multi;
        }
        return null;
    }

    protected abstract void warpTheMao(Map<String,Object> map);



}








